package com.pe1n.yangtaopai.view.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.adapter.MyActivityItemTwoItmRecyclerAdapter;
import com.pe1n.yangtaopai.adapter.MyActivityItemTwoItmRigthRecyclerAdapter;
import com.pe1n.yangtaopai.bean.ListtwoBean;
import com.pe1n.yangtaopai.bean.TwoTwoBean;
import com.pe1n.yangtaopai.presenter.PresenterIntemTwo;
import com.pe1n.yangtaopai.utils.URLConstant;
import com.pe1n.yangtaopai.view.interfacese.IViewIntemTwo;

import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;

public class ItemTwoListActivity extends AppCompatActivity implements IViewIntemTwo, View.OnClickListener {
    private Context mContent = this;
    private PresenterIntemTwo presenterIntemTwo;
    private List<TwoTwoBean.DataBean.ZranklistBean> listTwoTwoBean = new ArrayList<>();
    private List<TwoTwoBean.DataBean.AllranklistBean> listTwoTwoRightBean = new ArrayList<>();
    private List<TwoTwoBean.DataBean.ZranklistBean> list = new ArrayList<>();
    private List<Object>objects=new ArrayList<>();
    private ImageView imageViewlift_activityTwo, imageViewright_avtivity_Two;
    private TextView textViewCenter_activityTwo;
    private List<Object> objectList=new ArrayList<>();
    private ProgressBar progressBar;
    private String namea;
    private String id;
    private String stringUrl;
    private View header;
    private TwoTwoBean mBean;
    private XRecyclerView xRecyclerView;
    private MyActivityItemTwoItmRecyclerAdapter myActivityItemTwoRecyclerAdapter;
    private MyActivityItemTwoItmRigthRecyclerAdapter myActivityItemTwoItmRigthRecyclerAdapter;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item_two);
        namea = getIntent().getStringExtra("name");
        id = getIntent().getStringExtra("id");
        stringUrl = String.format(URLConstant.ListTWO1_REL, id);


        initView();
    }

    private void initView() {
        myActivityItemTwoItmRigthRecyclerAdapter = new MyActivityItemTwoItmRigthRecyclerAdapter(mContent, listTwoTwoRightBean);
        myActivityItemTwoRecyclerAdapter = new MyActivityItemTwoItmRecyclerAdapter(mContent, objectList);
        progressBar = (ProgressBar) findViewById(R.id.progressbar_activity_item_two);
        textViewCenter_activityTwo = (TextView) findViewById(R.id.textview_center_item_two_activity);
        textViewCenter_activityTwo.setText(namea);

        imageViewlift_activityTwo = (ImageView) findViewById(R.id.imageview_lift_item_two_activity);
        imageViewright_avtivity_Two = (ImageView) findViewById(R.id.imageview_right_item_two_activity);
        imageViewlift_activityTwo.setOnClickListener(this);
        imageViewright_avtivity_Two.setOnClickListener(this);
        //第一个适配器的绑定
        xRecyclerView = (XRecyclerView) findViewById(R.id.xrecyclerview_activity_item_two);
        xRecyclerView.setAdapter(myActivityItemTwoRecyclerAdapter);
        xRecyclerView.setLayoutManager(new LinearLayoutManager(mContent, OrientationHelper.VERTICAL, false));


        //头1
        header = LayoutInflater.from(mContent).inflate(R.layout.activity_item_two_header, (ViewGroup) findViewById(android.R.id.content), false);
        xRecyclerView.addHeaderView(header);



        ((RadioGroup) header.findViewById(R.id.rg_more)).setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i) {
                    case R.id.rbtn_more_left:
                        objectList.clear();
                        objectList.addAll(list);
                        myActivityItemTwoRecyclerAdapter.notifyDataSetChanged();
                        break;
                    case R.id.rbtn_more_right:
                        objectList.clear();
                        List<TwoTwoBean.DataBean.AllranklistBean> list2 = mBean.getData().getAllranklist();
                        objectList.addAll(list2);
                       // Log.e("tag",listTwoTwoRightBean.toString());
                        myActivityItemTwoRecyclerAdapter.notifyDataSetChanged();
                        break;
                }
            }
        });
        presenterIntemTwo = new PresenterIntemTwo(this);
        presenterIntemTwo.LoadItemTwoTwoData(stringUrl);
        ((TextView) header.findViewById(R.id.text_activity_item_two_header)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((TextView) header.findViewById(R.id.text_activity_item_two_header)).setText("已关注");
            }
        });


    }

    @Override
    public void showProgress() {
        progressBar.setVisibility(View.INVISIBLE);



    }

    @Override
    public void showLoadFailMsg() {

    }

    @Override
    public void LoadItemListTwoData(TwoTwoBean intemTwoTwoBean) {
        mBean = intemTwoTwoBean;
        list = mBean.getData().getZranklist();
        objectList.addAll(list);
        ((TextView) header.findViewById(R.id.textview_activity_two_gengxin)).setText("更新于" + intemTwoTwoBean.getData().getCataInfo().getUpdateDate());
        myActivityItemTwoRecyclerAdapter.notifyDataSetChanged();

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.imageview_lift_item_two_activity:
                finish();
                break;
            case R.id.imageview_right_item_two_activity:
                break;
        }
    }
}
